package metalink.admin;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;

import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;


public class DeleteStudentDetails extends ActionSupport{
	private int page;
    private String morepages;
	private Vector noofpages=new Vector();
	private int nextpage;
	private int currentpage;
	private String hasprevpage;
	private int prevpage;
	private int items;
	//private Vector pagelist=new Vector();
	private ArrayList<StudentDetailsVo> pagelist;
	private int result;
	ArrayList<StudentDetailsVo> list; 
	public ArrayList<StudentDetailsVo> getList() {
		return list;
	}

	public void setList(ArrayList<StudentDetailsVo> list) {
		this.list = list;
	}

	int[] student_id;
	
	public int[] getStudent_id() {
		return student_id;
	}

	public void setStudent_id(int[] student_id) {
		this.student_id = student_id;
	}

	public String execute(){
		try{
			Connect c=new Connect();
			for(int single_student_id:student_id){
				String email_id="";
				ResultSet rs=c.getResult("select email_id from student_details where student_id='"+single_student_id+"'");
				if(rs.next()){
					email_id=rs.getString("email_id");
				}
				c.dml("update student_details set status='Inactive' where student_id='"+single_student_id+"'");
				
				c.dml("delete from login_info where login_id='"+email_id+"'");
			}
			
			PopulateStudentsListMo populate=new PopulateStudentsListMo();
			list=populate.populatelist();
			result = list.size();
			pagelist =new ArrayList<StudentDetailsVo>();
			int p=getPage();
		    if(p==0)
		    {
		        setHasprevpage("false");
		    }
		    else
		    {
		        setHasprevpage("true");
		        setPrevpage(p-1);
		    }

		    setCurrentpage(p);

		    int count;
		    count=0;

		    int size=list.size();
		    setItems(size);
		    int pagesinlist=size/15;
		    while(count<=pagesinlist)
		    {
		        noofpages.add(count);
		        count++;
		    }
		    count=0;
		    while(count<15)
		    {

		        if(size>=(p*15)+count+1)
		        {
		            System.out.println(p);
		            pagelist.add(list.get((p*15)+count));
		            System.out.println((p*15)+count);
		            System.out.println("size"+pagelist.size());
		            count++;
		            setMorepages("true");
		            setNextpage(p+1);

		        }
		        else
		        {
		            setMorepages("false");
		            break;
		        }
		    }
			return SUCCESS;
		}
		
		catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getMorepages() {
		return morepages;
	}

	public void setMorepages(String morepages) {
		this.morepages = morepages;
	}

	public Vector getNoofpages() {
		return noofpages;
	}

	public void setNoofpages(Vector noofpages) {
		this.noofpages = noofpages;
	}

	public int getNextpage() {
		return nextpage;
	}

	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public String getHasprevpage() {
		return hasprevpage;
	}

	public void setHasprevpage(String hasprevpage) {
		this.hasprevpage = hasprevpage;
	}

	public int getPrevpage() {
		return prevpage;
	}

	public void setPrevpage(int prevpage) {
		this.prevpage = prevpage;
	}

	public int getItems() {
		return items;
	}

	public void setItems(int items) {
		this.items = items;
	}

	public ArrayList<StudentDetailsVo> getPagelist() {
		return pagelist;
	}

	public void setPagelist(ArrayList<StudentDetailsVo> pagelist) {
		this.pagelist = pagelist;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

}
